package chapter13.Z4;

public class Str4 {
    /*传闻StringBuilder比StringBuffer快,
比较一下，输出你的比较结果（拼接10万个相同的字符串，比较时间）。*/
    public static void main(String[] args) {
        StringBuilder s1 = new StringBuilder();
        long start1 = System.nanoTime();
        for (int i = 0; i <100000 ; i++) {
            s1.append("sb");
        }
        long end1 = System.nanoTime();
        StringBuffer s2 = new StringBuffer();
        long start2= System.nanoTime();
        for (int i = 0; i <100000 ; i++) {
            s1.append("sb");
        }
        long end2 = System.nanoTime();
        if ((end1-start1)-(end2-start2)>0){
            System.out.println("StringBuffer快");
        }else {
            System.out.println("StringBuilder快");
        }
    }
}
